﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BIOrdenes;
using System.Data;
using System.Runtime.Serialization;

namespace BLGestionOrdenes
{
    // Este atributo se encuentra en System.Runtime.Serialization
    [DataContract]
    public class LoginInfo: ILogin
    {
        internal LoginInfo(DataTable lpData)
        {
            _isAuthenticated = false;

            if (lpData.Rows.Count == 0)
                throw new InvalidOperationException("User information is missing");

            DataRow lvRowLogin = lpData.Rows[0];
            _login = lvRowLogin["login"].ToString();
            _password = lvRowLogin["password"].ToString();
            _userName = lvRowLogin["userName"].ToString();
            _rolName = lvRowLogin["rolName"].ToString();

            _isAuthenticated = true;
        }

        #region ILogin Members

        private bool _isAuthenticated;
        [DataMember]
        public bool IsAuthenticated
        {
            get { return _isAuthenticated; }            
        }

        internal string _login;
        [DataMember]
        public string Login
        {
            get { return _login;}
        }

        internal string _password;
        [DataMember]
        public string Password
        {
            get { return _password; }
        }

        internal string _userName;
        [DataMember]
        public string UserName
        {
            get { return _userName; }
        }

        internal string _rolName;
        [DataMember]
        public string RolName
        {
            get { return _rolName; }
        }

        #endregion
    }
}
